package com.system.reflect.demo01;

import java.lang.reflect.InvocationTargetException;

/**
 * @author DELL
 */
public class ReflectServiceImpl2 {
    private String name;

    /**
     * 构建方法含有参数的类
     * @param name
     */
    public ReflectServiceImpl2(String name){
        this.name = name;
    }
    public void sayHello(){
        System.err.println("hello "+ name);
    }
    /**
     * 通过反射生成带有参数的构建方法
     */
    public ReflectServiceImpl2 getInstance(){
        ReflectServiceImpl2 object = null;
        try {
            object = (ReflectServiceImpl2) Class.forName("com.system.reflect.demo01.ReflectServiceImpl2").getConstructor(String.class).newInstance("张三");
        } catch (ClassNotFoundException | InstantiationException | IllegalAccessException |
                 NoSuchMethodException | SecurityException | IllegalArgumentException |
                 InvocationTargetException e) {
            e.printStackTrace();

        }
        return object;
    }
}
